﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using System.Xml;

namespace Navigate
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();

            // 用doc对象读取文件.
            doc.Load(Application.StartupPath + "/employees.xml");

            // 把documentElement的名字加入TreeNode.
            TreeNode root = new TreeNode(doc.DocumentElement.Name);

            // treeView1作为一个基本根 把TreeNode对象加入Nodes里面
            treeView1.Nodes.Add(root);

            // 遍历DocumentElement里面所有子Node
            foreach (XmlNode node in doc.DocumentElement.ChildNodes)
            {
                TreeNode employee = new TreeNode("Employee ID :" +
                    node.Attributes["employeeid"].Value);

                root.Nodes.Add(employee);

                if (node.HasChildNodes)
                {
                    foreach (XmlNode childnode in node.ChildNodes)
                    {
                        TreeNode n2 = new TreeNode(childnode.Name + ":" + childnode.InnerText);
                        employee.Nodes.Add(n2);
                    }
                }


            }

        }
    }
}
